package com.xh.petdogexpert.expert.controller;

import java.util.HashMap;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.xh.petdogexpert.base.BaseController;
import com.xh.petdogexpert.base.ResponseData;
import com.xh.petdogexpert.expert.dto.ArticlePush;
import com.xh.petdogexpert.expert.service.IArticleService;

@RequestMapping(value = "expert/article")
@Controller
public class ArticleController extends BaseController {

	@Autowired
	IArticleService articleService;

	@RequestMapping(value = "/pushToAndroid")
	@ResponseBody
	public ResponseData pushToAndroid(ArticlePush article) throws Exception {

		Map<String, Object> content = new HashMap<String, Object>();

		content.put("title", article.getTitle());
		content.put("description", article.getDescription());
		Map<String, Object> custom_content = new HashMap<String, Object>();
		custom_content.put("id", article.getId());
		content.put("custom_content", custom_content);

		String msg = articleService.pushToAndroid(content);
		return new ResponseData(msg);
	}

	@RequestMapping(value = "/zan")
	@ResponseBody
	public ResponseData zan(@RequestParam(required = true) Integer id) {

		return new ResponseData(articleService.zan(id));
	}

	@RequestMapping(value = "/getArticleZan")
	@ResponseBody
	ResponseData getArticleZan(int id) {
		return new ResponseData(articleService.getArticleZan(id));
	}

	@RequestMapping(value = "/getArticleDetail")
	@ResponseBody
	public ResponseData getArticleDetail(Integer id) {

		ArticlePush articleDetail = articleService.getArticleDetail(id);

		return new ResponseData(articleDetail);
	}

	@RequestMapping(value = "/queryArticle")
	@ResponseBody
	public ResponseData queryArticle(ArticlePush articlePush, @RequestParam(defaultValue = "1") Integer pagenum,
			@RequestParam(defaultValue = "10") Integer pagesize) {
		if (articlePush == null)
			articlePush = new ArticlePush();

		return new ResponseData(articleService.queryArticlePushs(articlePush, pagenum, pagesize));
	}

}
